package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.system.domain.query.SysMessageSendRecordQuery;
import com.jcfk.system.domain.dto.SysMessageSendRecordDTO;
import com.jcfk.system.domain.dto.SysMessageSendRecordDetailsDTO;
import com.jcfk.system.service.SysMessageSendRecordService;

import java.util.List;

/**
 * 消息发送记录
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2023-12-29
 */
@Api(tags = {"消息发送记录管理"})
@RestController
@RequestMapping("sysmessagesendrecord")
public class SysMessageSendRecordController {
    @Autowired
    private SysMessageSendRecordService sysMessageSendRecordService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<SysMessageSendRecordQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询消息发送记录")
    @PostMapping("/queryByPage")
    @ResponseBody
    public RetPage<SysMessageSendRecordDTO> queryByPage(@RequestBody ReqPageParam<SysMessageSendRecordQuery> requestParam) {
        DataPage<SysMessageSendRecordDTO> page = new DataPage<SysMessageSendRecordDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            SysMessageSendRecordDTO.class);
        page = sysMessageSendRecordService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "SysMessageSendRecordQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取消息发送记录列表", notes = "获取消息发送记录列表", httpMethod = "POST")
    @PostMapping("getDetails")
    public RetResult<List<SysMessageSendRecordDetailsDTO>> getDetails(@RequestBody SysMessageSendRecordQuery query) {

        List<SysMessageSendRecordDetailsDTO> list = sysMessageSendRecordService.getDetails(query);

        return RetResult.ok(list);
    }

    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "SysMessageSendRecordQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取消息发送记录列表", notes = "获取消息发送记录列表", httpMethod = "POST")
    @PostMapping("getList")
    public RetResult<List<SysMessageSendRecordDTO>> getList(@RequestBody SysMessageSendRecordQuery query) {

        List<SysMessageSendRecordDTO> list = sysMessageSendRecordService.getList(query);

        return RetResult.ok(list);
    }


    /**
     *  消息发送记录
     * 根据id 查询详情
     */
    @ApiOperation("查询消息发送记录")
    @GetMapping("/get/{id}")
    @ResponseBody
    public RetResult<SysMessageSendRecordDTO> get(@PathVariable("id") String id) {
            SysMessageSendRecordDTO item = sysMessageSendRecordService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理消息发送记录
     */
    @ApiOperation("保存消息发送记录")
    @PostMapping("/save")
    @ResponseBody
    @RequestLogHeader(modular = "消息发送记录管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid SysMessageSendRecordDTO sysMessageSendRecord) {
        // 数据校验
        RetResult ret = sysMessageSendRecordService.isValid(sysMessageSendRecord);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(sysMessageSendRecord.getId())){
            // 新增
                sysMessageSendRecordService.insert(sysMessageSendRecord);
        } else{
            // 更新
                sysMessageSendRecordService.update(sysMessageSendRecord);
        }
        return RetResult.ok();

    }


    /**
     *  批量删除消息发送记录
     */
    @ApiOperation("批量删除消息发送记录")
    @ResponseBody
    @PostMapping("/delete")
    @RequestLogHeader(modular = "消息发送记录管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody SysMessageSendRecordDTO sysMessageSendRecord) {
        return RetResult.ok(sysMessageSendRecordService.removeBigBatch(sysMessageSendRecord.getIds()));
    }

}
